package com.d0326.homework;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;

/*读取一个D:/a.txt文件，显示Java关键字的个数
        ==========================a.txt文件内容=============================
        hello world interface class is good weather is good break swith interface
==========================================================================
interface 2
class 1
 break 1*/
public class TestFile {
    static int b = 0;
    static int c = 0;
    static int in = 0;

    public static void main(String[] args) {
        File file = new File("D:\\a.txt");
        try {
            Scanner sc = new Scanner(file);
            String str = sc.nextLine();
            System.out.println(str);
            String[] over = str.split(" ");//存入数组空格分隔
            for (int i = 0; i < over.length; i++) {
                if (over[i].equals("break")) {
                    b++;
                }
                if (over[i].equals("class")) {
                    c++;
                }
                if (over[i].equals("interface")) {
                    in++;
                }
                //System.out.println(over[i]);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        System.out.println("出现的break的次数为" + b);
        System.out.println("出现的class关键字的次数为" + c);
        System.out.println("出现的interface关键字的次数为" + in);
    }
}
